package ua.com.abakumov.android.prostopleer.util

import android.app.{Activity, AlertDialog}
import android.widget.{EditText, Toast, TextView}
import android.content.Context
import android.view.inputmethod.InputMethodManager

/**
 * UI utils object

 * @author alexander-abakumov
 *         Date: 31.08.12
 */
object UI {
    /**
     * Alert dialog
     *
     * @param title   title text
     * @param message message text
     * @param context context (e.g. reference to Activity instance)
     */
    def alert(title: String, message: String, context: Activity) {
        val alert: AlertDialog = new AlertDialog.Builder(context).create
        alert.setTitle(title)
        alert.setMessage(message)
        alert.show()
    }

    def toast(message: String, context: Context) {
        Toast.makeText(context, message, 6000).show()
    }

    def createTextView(text: String, context: Activity): TextView = {
        val v = new TextView(context)
        v.setText(text)
        v
    }

    def hideKeyboard(textEdit : EditText, context: Context) {
      val inputManager = context.getSystemService(Context.INPUT_METHOD_SERVICE).asInstanceOf[InputMethodManager]
      inputManager.hideSoftInputFromWindow(textEdit.getWindowToken, InputMethodManager.HIDE_NOT_ALWAYS)
    }
}